import QtQuick 2.0
import QtMultimedia 5.12

Rectangle {
    width: img.width
    height: img.height
    color: Qt.rgba(0,0,0,0)

    ListModel{
        id:listModel
        ListElement{ name:"volume_close" ; source:"qrc:/Images/volume_close.png"}
        ListElement{ name:"volume_low" ; source:"qrc:/Images/volume_low.png"}
        ListElement{ name:"volume_high" ; source:"qrc:/Images/volume_high.png"}
    }

    Image{
        id:img
        width: 38
        opacity: 0.8
        objectName: "volume_low"
        source:"qrc:/Images/volume_low.png"
        fillMode: Image.PreserveAspectFit

    }

    MediaPlayer{
        id:mediaPlayer
        source:"qrc:/Audio/Stars_Childsion.mp3"
        autoPlay: true  // 是否自动播放
        volume:0.5  // 音量大小

        onStopped: {
            mediaPlayer.play();
        }
    }

    MouseArea{
        anchors.fill:parent
        onClicked: {
            var objName = img.objectName.toString()
            for(var i=0;i!==3;++i){
                var name = listModel.get(i).name
                if(name === objName) {
                    var j = (i+1)%3
                    img.source = listModel.get(j).source
                    img.objectName = listModel.get(j).name
                    objName = img.objectName
                    break;
                }
            }
            if("volume_close" === objName){
                mediaPlayer.volume = 0
            }else if("volume_low" === objName){
                mediaPlayer.volume = 0.5
            }else{
                mediaPlayer.volume = 1.0
            }
        }
    }

}
